using System.Data;
using NGrid.Models;
using Orchard.ContentManagement.MetaData;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace NGrid
{
    public class Migrations : DataMigrationImpl
    {
        public int Create()
        {
			SchemaBuilder.CreateTable("NGridRecord", table => table.ContentPartRecord()
				.Column("HasPages", DbType.Boolean));

            ContentDefinitionManager.AlterPartDefinition(typeof(NGridPart).Name, cfg => cfg.Attachable());

            return 1;
        }

        public int UpdateFrom1()
        {
            SchemaBuilder.DropTable("NGridRecord");
            SchemaBuilder.CreateTable("NGridRecord", table => table.ContentPartRecord()
                .Column("EnablePaging", DbType.Boolean)
                .Column("EnableSorting", DbType.Boolean));

            return 2;
        }

        public int UpdateFrom2() 
        {
            SchemaBuilder.AlterTable("NGridRecord", table => table.AddColumn("TargetTableName", DbType.String));

            return 3;
        }
    }
}